//
//  NoticeSettingViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/6/2.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "NoticeSettingViewController.h"
#import <EventKit/EventKit.h>
#import "NoticeRepeatViewController.h"

@interface NoticeSettingViewController ()
@property(nonatomic,weak)IBOutlet UIImageView *listBg;
@property(nonatomic,strong)NSMutableArray *weekdays;
@property(nonatomic,weak)IBOutlet UILabel *repeatLab;
@property(nonatomic,weak)IBOutlet UILabel *preniumTimeLab;
@property(nonatomic,weak)IBOutlet UITextField *remarkText;
@property(nonatomic,weak)IBOutlet UISwitch *switchBtn;
@property(nonatomic,weak)IBOutlet UIDatePicker *pickerView;
@end

@implementation NoticeSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"编辑闹钟";
    [self setNavRightBtn:@"保存" color:nil];
    [self.listBg setImage:[[UIImage imageNamed:@"cornerBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"cornerBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"cornerBg"].size.height/2]];
    [self handleWeekStr];
}
-(void)rightbuttonPressed:(id)sender{
    ClockModel *model = [[ClockModel alloc]init];
    model.date = self.pickerView.date;
    model.tagStr = self.remarkText.text;
    model.isLater = self.switchBtn.isOn;
    model.repeatStr = self.repeatLab.text;
    model.isOn = YES;
    if (self.block) {
        self.block(model);
    }
    [self.rt_navigationController popViewControllerAnimated:YES complete:nil];
}
-(IBAction)repeatBtnPressed:(id)sender{
    NoticeRepeatViewController *repeatVC = [[NoticeRepeatViewController alloc]init];
    repeatVC.weekdaysFromSetting = self.weekdays;
    kWeakSelf;
    repeatVC.block = ^(NSArray * _Nonnull weeksDays) {
        kStrongSelf;
        [strongSelf.weekdays removeAllObjects];
        [strongSelf.weekdays addObjectsFromArray:weeksDays];
        [strongSelf handleWeekStr];
    };
    [self.rt_navigationController pushViewController:repeatVC animated:YES complete:nil];
}
-(void)handleWeekStr{
    if ([self.weekdays count]>0) {
        NSMutableString *str = [[NSMutableString alloc]initWithCapacity:0];
        for (int i=0; i<[self.weekdays count]; i++) {
            NSString *strWeek = [NSString stringWithFormat:@"%@",[self.weekdays objectAtIndex:i]];
            [str appendFormat:@"%@", strWeek];
            [str appendFormat:@" "];
        }
        self.repeatLab.text = str;
    }else{
        self.repeatLab.text = @"永不";
    }
}
-(IBAction)selectBeforeTime:(id)sender{
    [SMBRadioPickerView showPickerViewWithStrings:@[@"12小时",@"6小时",@"3小时",@"2小时",@"1小时",@"半小时"] completion:^(NSString *selectedString) {
        self.preniumTimeLab.text = selectedString;
    }];
}
- (NSMutableArray *)weekdays {
    if (!_weekdays) {
        _weekdays = [NSMutableArray array];
    }
    return _weekdays;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
